//
//  Registration.m
//  ArtCircle
//
//  Created by sunbin on 2017/5/19.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "Registration.h"
#import "ThreeInputBox.h"


#import "PasswordLogin.h"

@interface Registration ()
@property (nonatomic ,strong) ThreeInputBox *three;
@end

@implementation Registration

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.three.account.text = _phone;
    
    [self.navigationController.view showLoadFinish:_msg showLoc:bottom];
    
    
    [[NSNotificationCenter defaultCenter] postNotificationName:FIRSTTIMECOUBTDOWN object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"注册";
    
    _three = self.contentView.inputBoxView.three;
    
    [_three.submitBtn setTitle:@"完成注册" forState:UIControlStateNormal];
    
    WEAKSELF;
    _three.nextStepHandler = ^(NSString *account, NSString *pwd, NSString *code, NSInteger make ,UIButton *sender) {
#pragma make 重发 注册
        [weakSelf.navigationController.view showLoading:@[@"正在发送",@"正在注册"][make]];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            
            [weakSelf.navigationController.view hideHUD];
            
            [[AccountManage sharedAccountManage] request:make apiTy:API_Registration params:@[@{@"phone":weakSelf.phone},@{@"phone":account ,@"code":code ,@"password":pwd}][make] success:^(NSDictionary *results, NSString *successMsg) {

                make == 0?[weakSelf getCode:sender]:[weakSelf easeMobRegisterWithAccount:account pwd:pwd];
                
                if (make == 0) {
                    [weakSelf.navigationController.view showLoadFinish:successMsg showLoc:bottom];
                }
                

                
            } failed:^(WrapperEnumError errorty, NSString *msg) {
                
            }];
            
            
        });

        
   
    };
    
}

- (void)getCode:(UIButton *)sender{
    [sender startTime:59 title:@"重新发送(60s)" waitTittle:@"s" respond:^(BOOL isPlayComple) {
        if (isPlayComple) {
            
        }
    }];


}



#pragma make -注意 服务器已经注册环信
- (void)easeMobRegisterWithAccount:(NSString *)account pwd:(NSString *)pwd{

#pragma make 跳转到密码登录页 保存账号
    
    PasswordLogin *login = [[PasswordLogin alloc] init];
    login.account = account;
    [self.navigationController pushViewController:login animated:NO];
    

    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


- (BOOL)isShowAuthorizedLoginView {
    return YES;
}

- (BOOL)isShowAccountHeaderView {
    return NO;
}

- (InputBoxType)getInputBoxType {
    return InputBoxTypeThree;
}

@end
